package com.yq.comm.invoker;

import com.yq.comm.command.InitContextCommand;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yq on 16-8-14.
 */
public class InitContextCommandInvoker {
    private List<InitContextCommand> history = new ArrayList<InitContextCommand>();
    private int lastCommand = 0;
    public void executeCommand(InitContextCommand command){
        command.execute();
        history.add(command);
        lastCommand = history.size() -1;
    }
    public void redoNextCommand(){
        lastCommand++;
        if(lastCommand < history.size()){
            history.get(lastCommand).execute();
        }
    }
    public void undoLastCommand(){
        history.get(lastCommand).undo();
        lastCommand--;
    }
}
